home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Environments / Clean 1.2.4 / IOInterface / windowDef.icl < prev    next >
Encoding:
Modula Implementation  |  1995-03-10  |  12.5 KB  |  265 lines  |  [TEXT/3PRM]

  1. implementation module windowDef;
  2.  
  3.  
  4. //
  5. //    WindowDefinitions:
  6. //
  7.  
  8.  
  9. import    StdInt;
  10. import    commonDef;
  11. from    ioState            import IOState;
  12. from    deltaPicture    import Picture, Rectangle, DrawFunction;
  13.  
  14.  
  15. ::    WindowDef *s *io
  16.     =    ScrollWindow    WindowId WindowPos WindowTitle
  17.                         ScrollBarDef ScrollBarDef
  18.                         PictureDomain MinimumWindowSize InitialWindowSize
  19.                         (UpdateFunction s) [WindowAttribute s io]
  20.     |    FixedWindow WindowId WindowPos WindowTitle
  21.                         PictureDomain (UpdateFunction s) [WindowAttribute s io];
  22.  
  23. ::    WindowId            :== Int;
  24. ::    WindowPos            :== (!Int, !Int);
  25. ::    WindowTitle            :== String;
  26. ::    ScrollBarDef        =    ScrollBar ThumbValue ScrollValue;
  27. ::    ThumbValue            =    Thumb  Int;
  28. ::    ScrollValue            =    Scroll Int;
  29. ::    MinimumWindowSize    :== (!Int, !Int);
  30. ::    InitialWindowSize    :== (!Int, !Int);
  31. ::    UpdateArea            :== [Rectangle];
  32. ::    UpdateFunction    *s    :== UpdateArea -> (s -> (s,[DrawFunction]));
  33.  
  34. ::    WindowAttribute    *s *io
  35.     =    Activate    (WindowFunction s io)
  36.     |    Deactivate    (WindowFunction s io)
  37.     |    GoAway        (WindowFunction s io)
  38.     |    Mouse        SelectState (MouseFunction s io)
  39.     |    Keyboard    SelectState (KeyboardFunction s io)
  40.     |    Cursor        CursorShape
  41.     |    StandByWindow;
  42.  
  43. ::    WindowFunction        *s *io :== s -> *(io -> (s, io));        
  44. ::    MouseFunction        *s *io :== MouseState    -> (s -> *(io -> (s, io)));
  45. ::    KeyboardFunction    *s *io :== KeyboardState-> (s -> *(io -> (s, io)));
  46.  
  47. ::    CursorShape    =    StandardCursor    | BusyCursor     | IBeamCursor
  48.                 |    CrossCursor        | FatCrossCursor | ArrowCursor | HiddenCursor;
  49.  
  50.  
  51. IsScrollWindow    :: !(WindowDef s io) -> Bool;
  52. IsScrollWindow (ScrollWindow id pos t h v pd min init f as) =  True;
  53. IsScrollWindow window =  False;
  54.  
  55. WindowDefGetWindowId    :: !(WindowDef s io) -> WindowId;
  56. WindowDefGetWindowId (ScrollWindow id pos t h v pd min init f as) =  id;
  57. WindowDefGetWindowId (FixedWindow  id pos t     pd          f as) =  id;
  58.     
  59. WindowDefGetPosition    :: !(WindowDef s io) -> WindowPos;
  60. WindowDefGetPosition (ScrollWindow id pos t h v pd min init f as) =  pos;
  61. WindowDefGetPosition (FixedWindow  id pos t     pd          f as) =  pos;
  62.     
  63. WindowDefGetTitle    :: !(WindowDef s io) -> String;
  64. WindowDefGetTitle (ScrollWindow id pos t h v pd min init f as) =  t;
  65. WindowDefGetTitle (FixedWindow  id pos t     pd          f as) =  t;
  66.  
  67. WindowDefGetScrollBarDefs    :: !(WindowDef s io) -> (!ScrollBarDef, !ScrollBarDef);
  68. WindowDefGetScrollBarDefs (ScrollWindow id pos t h v pd min init f as) =  (h, v);
  69.  
  70. WindowDefGetPictureDomain    :: !(WindowDef s io) -> PictureDomain;
  71. WindowDefGetPictureDomain (ScrollWindow id pos t h v pd min init f as) =  pd;
  72. WindowDefGetPictureDomain (FixedWindow  id pos t     pd          f as) =  pd;
  73.  
  74. WindowDefGetMinimumSize    :: !(WindowDef s io) -> MinimumWindowSize;
  75. WindowDefGetMinimumSize (ScrollWindow id pos t h v pd min init f as) =  min;
  76. WindowDefGetMinimumSize (FixedWindow  id pos t pd=:((xl,yl), (xr,yr)) f as) = (xr-xl, yr-yl);
  77.  
  78. WindowDefGetInitialSize    :: !(WindowDef s io) -> InitialWindowSize;
  79. WindowDefGetInitialSize (ScrollWindow id pos t h v pd min init f as) =  init;
  80. WindowDefGetInitialSize (FixedWindow  id pos t pd=:((xl,yl), (xr,yr)) f as) = (xr-xl, yr-yl);
  81.  
  82. WindowDefGetUpdate    :: !(WindowDef s io) -> UpdateFunction s;
  83. WindowDefGetUpdate (ScrollWindow id pos t h v pd min init f as) =  f;
  84. WindowDefGetUpdate (FixedWindow  id pos t     pd          f as) =  f;
  85.  
  86. WindowDefHasAttribute    :: !(WindowDef s io) !(WindowAttribute s io) -> Bool;
  87. WindowDefHasAttribute (ScrollWindow id pos t h v pd min init f as) a
  88.     =     WindowAttributesHaveAttribute as a;
  89. WindowDefHasAttribute (FixedWindow  id pos t     pd          f as) a
  90.     =     WindowAttributesHaveAttribute as a;
  91.  
  92. WindowDefIsStandBy    :: !(WindowDef s io) -> Bool;
  93. WindowDefIsStandBy (ScrollWindow id pos t h v pd min init f as)
  94.     =     WindowAttributesHaveAttribute as StandByWindow;
  95. WindowDefIsStandBy (FixedWindow id pos t pd f as)
  96.     =     WindowAttributesHaveAttribute as StandByWindow;
  97.  
  98. WindowAttributesHaveAttribute :: ![WindowAttribute s io] !(WindowAttribute s io) -> Bool;
  99. WindowAttributesHaveAttribute [Activate        a        : as] (Activate        a` ) =  True;
  100. WindowAttributesHaveAttribute [Deactivate    d        : as] (Deactivate    d` ) =  True;
  101. WindowAttributesHaveAttribute [GoAway        g        : as] (GoAway        g` ) =  True;
  102. WindowAttributesHaveAttribute [Keyboard        ks kf    : as] (Keyboard    ks` kf`) =  True;
  103. WindowAttributesHaveAttribute [Mouse        ms mf    : as] (Mouse    ms` mf`) =  True;
  104. WindowAttributesHaveAttribute [Cursor        s        : as] (Cursor        s` ) =  True;
  105. WindowAttributesHaveAttribute [StandByWindow        : as] StandByWindow         =  True;
  106. WindowAttributesHaveAttribute [a : as] a`    =  WindowAttributesHaveAttribute as a`;
  107. WindowAttributesHaveAttribute as a            =  False;
  108.  
  109. WindowDefGetActivate    :: !(WindowDef s io) -> WindowFunction s io;
  110. WindowDefGetActivate (ScrollWindow id pos t h v pd min init f as)
  111.     =     GetWindowAttributeFunction as (Activate LazyWindowFunction);
  112. WindowDefGetActivate (FixedWindow id pos t pd f as)
  113.     =     GetWindowAttributeFunction as (Activate LazyWindowFunction);
  114.  
  115. GetWindowAttributeFunction    :: ![WindowAttribute s io] !(WindowAttribute s io)
  116.     ->    WindowFunction s io;
  117. GetWindowAttributeFunction [Activate    a : as] (Activate    a`) = a;
  118. GetWindowAttributeFunction [Deactivate    d : as] (Deactivate    d`) = d;
  119. GetWindowAttributeFunction [GoAway        g : as] (GoAway        g`) = g;
  120. GetWindowAttributeFunction [a : as] a`    = GetWindowAttributeFunction as a`;
  121. GetWindowAttributeFunction as a            = LazyWindowFunction;
  122.  
  123. LazyWindowFunction :: *s *io -> (*s, *io);
  124. LazyWindowFunction s io = (s, io);
  125.  
  126. WindowDefGetDeactivate    :: !(WindowDef s io) -> WindowFunction s io;
  127. WindowDefGetDeactivate (ScrollWindow id pos t h v pd min init f as)
  128.     =     GetWindowAttributeFunction as (Deactivate LazyWindowFunction);
  129. WindowDefGetDeactivate (FixedWindow id pos t pd f as)
  130.     =     GetWindowAttributeFunction as (Deactivate LazyWindowFunction);
  131.  
  132. WindowDefGetGoAway    :: !(WindowDef s io) -> WindowFunction s io;
  133. WindowDefGetGoAway (ScrollWindow id pos t h v pd min init f as)
  134.     =     GetWindowAttributeFunction as (GoAway LazyWindowFunction);
  135. WindowDefGetGoAway (FixedWindow id pos t pd f as)
  136.     =     GetWindowAttributeFunction as (GoAway LazyWindowFunction);
  137.  
  138. WindowDefGetCursor    :: !(WindowDef s io) -> CursorShape;
  139. WindowDefGetCursor (ScrollWindow id pos t h v pd min init f as)
  140.     =     GetWindowAttributeCursor as;
  141. WindowDefGetCursor (FixedWindow id pos t pd f as)
  142.     =     GetWindowAttributeCursor as;
  143.  
  144. GetWindowAttributeCursor    :: ![WindowAttribute s io] -> CursorShape;
  145. GetWindowAttributeCursor [Cursor shape : as] =  shape;
  146. GetWindowAttributeCursor [a : as]    =  GetWindowAttributeCursor as;
  147. GetWindowAttributeCursor as            =  StandardCursor;
  148.  
  149. WindowDefGetKeyboard    :: !(WindowDef s io) -> (!SelectState, !KeyboardFunction s io);
  150. WindowDefGetKeyboard (ScrollWindow id pos t h v pd min init f as)
  151.     =     GetWindowAttributeKeyboard as;
  152. WindowDefGetKeyboard (FixedWindow id pos t pd f as)
  153.     =     GetWindowAttributeKeyboard as;
  154.  
  155. WindowDefGetMouse    :: !(WindowDef s io) -> (!SelectState, !MouseFunction s io);
  156. WindowDefGetMouse (ScrollWindow id pos t h v pd min init f as)
  157.     =     GetWindowAttributeMouse as;
  158. WindowDefGetMouse (FixedWindow id pos t pd f as)
  159.     =     GetWindowAttributeMouse as;
  160.  
  161. GetWindowAttributeKeyboard    :: ![WindowAttribute s io] -> (!SelectState, !KeyboardFunction s io);
  162. GetWindowAttributeKeyboard [Keyboard ks kf : as] =  (ks, kf);
  163. GetWindowAttributeKeyboard [a : as]    =  GetWindowAttributeKeyboard as;
  164. GetWindowAttributeKeyboard as        =  (Unable, LazyDeviceFunction);
  165.  
  166. GetWindowAttributeMouse    :: ![WindowAttribute s io] -> (!SelectState, !MouseFunction s io);
  167. GetWindowAttributeMouse [Mouse ms mf : as] =  (ms, mf);
  168. GetWindowAttributeMouse [a : as]    =  GetWindowAttributeMouse as;
  169. GetWindowAttributeMouse as            =  (Unable, LazyDeviceFunction);
  170.  
  171. // LazyDeviceFunction    :: t * s * io -> (*s, *io);
  172. LazyDeviceFunction t s io =  (s, io);
  173.     
  174. ScrollBarDefGetValues :: !ScrollBarDef -> (!Int, !Int);
  175. ScrollBarDefGetValues (ScrollBar (Thumb t) (Scroll s)) =  (t, s);
  176.  
  177. WindowDefSetPictureDomain :: !PictureDomain !(WindowDef s io) -> WindowDef s io;
  178. WindowDefSetPictureDomain pd (ScrollWindow id pos t h v pd` min init f as)
  179.     =     ScrollWindow id pos t h v pd min init f as;
  180. WindowDefSetPictureDomain pd (FixedWindow id pos t pd` f as)
  181.     =     FixedWindow id pos t pd f as;
  182.  
  183. WindowDefSetUpdate :: !(UpdateFunction s) !(WindowDef s io) -> WindowDef s io;
  184. WindowDefSetUpdate f (ScrollWindow id pos t h v pd min init f` as)
  185.     =     ScrollWindow id pos t h v pd min init f as;
  186. WindowDefSetUpdate f (FixedWindow id pos t pd f` as)
  187.     =     FixedWindow id pos t pd f as;
  188.  
  189. WindowDefSetActivate :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
  190. WindowDefSetActivate a (ScrollWindow id pos t h v pd min init f as)
  191.     =     ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (Activate a));
  192. WindowDefSetActivate a (FixedWindow id pos t pd f as)
  193.     =     FixedWindow id pos t pd f (SetWindowAttributeFunction as (Activate a));
  194.  
  195. WindowDefSetDeactivate :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
  196. WindowDefSetDeactivate da (ScrollWindow id pos t h v pd min init f as)
  197.     =     ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (Deactivate da));
  198. WindowDefSetDeactivate da (FixedWindow id pos t pd f as)
  199.     =     FixedWindow id pos t pd f (SetWindowAttributeFunction as (Deactivate da));
  200.  
  201. WindowDefSetGoAway :: !(WindowFunction s io) !(WindowDef s io) -> WindowDef s io;
  202. WindowDefSetGoAway ga (ScrollWindow id pos t h v pd min init f as)
  203.     =     ScrollWindow id pos t h v pd min init f (SetWindowAttributeFunction as (GoAway ga));
  204. WindowDefSetGoAway ga (FixedWindow id pos t pd f as)
  205.     =     FixedWindow id pos t pd f (SetWindowAttributeFunction as (GoAway ga));
  206.  
  207. SetWindowAttributeFunction :: ![WindowAttribute s io] !(WindowAttribute s io)
  208.     ->    [WindowAttribute s io];
  209. SetWindowAttributeFunction [Activate    a    : as] f=:(Activate        a`) =  [f : as];
  210. SetWindowAttributeFunction [Deactivate    d    : as] f=:(Deactivate    d`) =  [f : as];
  211. SetWindowAttributeFunction [GoAway        g    : as] f=:(GoAway        g`) =  [f : as];
  212. SetWindowAttributeFunction [a : as] a`    = [a : SetWindowAttributeFunction as a`];
  213. SetWindowAttributeFunction as a`        = [a`];
  214.  
  215. WindowDefSetScrollBarDefs    :: !(!(!Int,!Int), !(!Int,!Int)) !(WindowDef s io) -> WindowDef s io;
  216. WindowDefSetScrollBarDefs scrollBars (ScrollWindow id pos t h v pd min init f as)
  217.     =    ScrollWindow id pos t hBar vBar pd min init f as;
  218.     where {
  219.         hBar                = ScrollBar (Thumb hThumb) (Scroll hScroll);
  220.         vBar                = ScrollBar (Thumb vThumb) (Scroll vScroll);
  221.         (hThumb, hScroll)    = hVals;
  222.         (vThumb, vScroll)    = vVals;
  223.         (hVals,    vVals)        = scrollBars;
  224.     };
  225. WindowDefSetScrollBarDefs scrollBars window =  window;
  226.  
  227. WindowDefSetMinimumSize    :: !MinimumWindowSize !(WindowDef s io) -> WindowDef s io;
  228. WindowDefSetMinimumSize min (ScrollWindow id pos t h v pd min` init f as)
  229.     =     ScrollWindow id pos t h v pd min init f as;
  230. WindowDefSetMinimumSize min window =  window;
  231.     
  232. WindowDefSetCursor :: !CursorShape !(WindowDef s io) -> WindowDef s io;
  233. WindowDefSetCursor shape (ScrollWindow id pos t h v pd min init f as)
  234.     =     ScrollWindow id pos t h v pd min init f (SetWindowCursor as (Cursor shape));
  235. WindowDefSetCursor shape (FixedWindow id pos t pd f as)
  236.     =     FixedWindow id pos t pd f (SetWindowCursor as (Cursor shape));
  237.     
  238. SetWindowCursor :: ![WindowAttribute s io] !(WindowAttribute s io) -> [WindowAttribute s io];
  239. SetWindowCursor [Cursor shape : as] cursor = [cursor : as];
  240. SetWindowCursor [a : as] cursor = [a : SetWindowCursor as cursor];
  241. SetWindowCursor as         cursor = [cursor];
  242.  
  243. WindowDefSetKeyboard :: !SelectState !(KeyboardFunction s io) !(WindowDef s io) -> WindowDef s io;
  244. WindowDefSetKeyboard ks kf (ScrollWindow id pos t h v pd min init f as)
  245.     =     ScrollWindow id pos t h v pd min init f (SetWindowAttributeDevice as (Keyboard ks kf));
  246. WindowDefSetKeyboard ks kf (FixedWindow id pos t pd f as)
  247.     =     FixedWindow id pos t pd f (SetWindowAttributeDevice as (Keyboard ks kf));
  248.  
  249. WindowDefSetMouse :: !SelectState !(MouseFunction s io) !(WindowDef s io) -> WindowDef s io;
  250. WindowDefSetMouse ms mf (ScrollWindow id pos t h v pd min init f as)
  251.     =     ScrollWindow id pos t h v pd min init f (SetWindowAttributeDevice as (Mouse ms mf));
  252. WindowDefSetMouse ms mf (FixedWindow id pos t pd f as)
  253.     =     FixedWindow id pos t pd f (SetWindowAttributeDevice as (Mouse ms mf));
  254.  
  255. SetWindowAttributeDevice :: ![WindowAttribute s io] !(WindowAttribute s io)
  256.     ->    [WindowAttribute s io];
  257. SetWindowAttributeDevice [Keyboard    ks kf : as] (Keyboard    ks` kf`) = [Keyboard    ks` kf` : as];
  258. SetWindowAttributeDevice [Mouse        ms mf : as] (Mouse        ms` mf`) = [Mouse        ms` mf` : as];
  259. SetWindowAttributeDevice [a : as] a`    = [a : SetWindowAttributeDevice as a`];
  260. SetWindowAttributeDevice as a`            = as;
  261.  
  262. WindowDefGetFinalMinimumSize    :: !(WindowDef s io) -> MinimumWindowSize;
  263. WindowDefGetFinalMinimumSize (ScrollWindow id pos t h v pd min init f as) =  (48, 1);
  264. WindowDefGetFinalMinimumSize (FixedWindow  id pos t     pd          f as) =  (32, 1);
  265.